<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<link rel="stylesheet" rev="stylesheet"
	href="/products/css/faq_base_v4.css" type="text/css" media="screen" />
<link rel='stylesheet' id='dt-main-css' href='/products/css/main.css'
	type='text/css' media='all' />
<link rel='stylesheet' id='dt-custom.less-css'
	href='/products/css/custom.css' type='text/css' media='all' />

</head>
<style>
.faq_list ol li{
	line-height: 28px;
}
</style>
<%@ include file="head.jsp"%>
<body style="min-height: 65%">
	<div id="newQuestion"
		style="margin: 0 auto;background-color: #f0f0f0;position: fixed;left: 40%;top:30%;display: none">
		<textarea rows="5" cols="60" id="content" maxlength="300" ></textarea>
		<div>
			<span>手机号码:</span><input type="text" maxlength="30"
				value="${contact}" id="contact" style="width: 70%">
			<button onclick="saveQuestion()" style="float:right;cursor: pointer;">保存</button>
		</div>
	</div>
	<div id="replyContent"
		style="margin: 0 auto;background-color: #f0f0f0;position: fixed;left: 35%;top:30%;display: none">
		<textarea rows="5" cols="60" id="rContent" maxlength="300"></textarea>
		<button onclick="saveReply()">保存</button>
	</div>
	<div>
		<div style="float: left;width: 25%">
			<c:if test="${adminLvl>0 }">
				<div>
					<h2>
						<button id="messageBtn" style="cursor: pointer;width: 150px;"
							onclick="messageBtn()">用户留言回复</button>
					</h2>
					<br>
					<h2>
						<button id="realNameComplaintBtn"
							style="cursor: pointer;width: 150px;"
							onclick="realNameComplaintBtn()">实名验证申诉单处理</button>
					</h2>
					<br>
					<h2>
						<button id="nomalComplaintBtn"
							style="cursor: pointer;width: 150px;"
							onclick="nomalComplaintBtn()">普通申诉单处理</button>
					</h2>
					<br>
				</div>
			</c:if>
			&nbsp;
		</div>
		<div style="float: left" id="message">
			<div class="content faq_list">
				<c:if test="${adminLvl<1 }">
					<h2 style="text-align: center;">请将您的想法留言给客服</h2>
				</c:if>
				<c:if test="${adminLvl>0 }">
					<h2 style="text-align: center;">用户留言</h2>
				</c:if>
				<c:if test="${adminLvl<1 }">
					<div><button id="add" style="float: right">新增留言</button></div>
				</c:if>
				<input type="text"  placeholder="请输入昵称" id="complaintQueryText" value="${complaintQueryText}">
				<button id="complaintQueryBtn" >查询</button>
				<br>
				<ol  style="color:black; ">
					<c:forEach items="${questions}" var="question" varStatus="status">
						<li style="color: rgb(156, 154, 156);font-size: 12px;">网&nbsp;&nbsp;友:<c:if test="${empty question.questionName}">
							游客
							</c:if> 
							<c:if test="${!empty question.questionName}">
							${question.questionName}
							</c:if> &nbsp;&nbsp;&nbsp;&nbsp;<fmt:formatDate value="${question.date}" pattern="yyyy-MM-dd HH:mm:ss"/>
							<br><span style="word-wrap:break-word;color: rgb(102, 102, 102)">咨询类容：${question.question } </span><c:if test="${adminLvl>0 }">
								<br>&nbsp;联系方式:${question.contact }
							</c:if> <c:if test="${adminLvl>0&& empty question.answer}">
								<button id="reply" onclick="markQuestionId(${question.id})"
									style="float:right;margin-top: -3%">回复</button>
							</c:if> <c:if test="${adminLvl>0}">
								<button id="del" onclick="del(${question.id})"
									style="float:right;margin-top: -3%">删除</button>
							</c:if> <c:if test="${!empty question.answer}">
								<br>
								<span style="color: rgb(255, 101, 0)">客服回复：${question.answer}</span><span style="float: right;"><fmt:formatDate value="${question.answerDate}" pattern="yyyy-MM-dd HH:mm:ss"/></span>
							</c:if></li>
					</c:forEach>

					<c:if test="${total >10}">
						<div class="paginator" role="navigation">
							<div class="page-links">
								<c:forEach begin="0" end="${maxPageNo-1 }" varStatus="status">
									<c:choose>
										<c:when test="${status.index==pageNo }">
											<a class="act"
												href="customerservicecenter?pageIndex=${status.index}&showPage=question">${status.count }</a>
										</c:when>
										<c:otherwise>
											<a href="customerservicecenter?pageIndex=${status.index}&showPage=question">${status.count }</a>
										</c:otherwise>
									</c:choose>

								</c:forEach>
							</div>
							<div class="page-nav">
								<c:if test="${pageNo>0 }">
									<a href="customerservicecenter?pageIndex=${pageNo-1}&showPage=question"
										class="nav-prev">前一页</a>
								</c:if>
								<c:if test="${pageNo<maxPageNo-1 }">
									<a href="customerservicecenter?pageIndex=${pageNo+1}&showPage=question"
										class="nav-next">后一页</a>
								</c:if>
							</div>
						</div>
					</c:if>


				</ol>
			</div>
		</div>
		<div style="float: left" id="realNameComplaint">
			<div class="content faq_list">
				<h2 style="text-align: center;">实名验证申诉单</h2>
				<input type="text"  placeholder="请输入账号" id="complaintRealNameQueryText" value="${complaintRealNameQueryText}">
				<button id="complaintRealNameQueryBtn" >查询</button>
				<br>
				<ol  style="color:black; ">
					<c:forEach items="${complaintsTrueName}" var="complaint"
						varStatus="status">
						<li id="${complaint.id}">&nbsp;申诉账号:${complaint.userAcc}
							<br>&nbsp;真实姓名:${complaint.trueName } <br>&nbsp;身份证号:${complaint.idNumber }
							<br>&nbsp;联系方式:${complaint.contact } <!-- 							<c:if test="${adminLvl>0&& empty complaint.answer}"> -->
							<!-- 								<button id="replyRealName" onclick="markComplaintId(${complaint.id})" -->
							<!-- 									style="float:right;margin-top: -3%">回复</button> -->
							<!-- 							</c:if> --> 
							<c:if test="${adminLvl>0}">
								<button id="del" onclick="delComplaint(${complaint.id})"
									style="float:right;margin-top: -3%">删除</button>
							</c:if> <!-- 							<c:if test="${!empty complaint.answer}"> --> <!-- 								<br> -->
							<!-- 								<span>&nbsp;${complaint.answerName}回复：${complaint.answer}</span> -->
							<!-- 							</c:if> --></li>
					</c:forEach>
					<c:if test="${totalComplaintsTrueName >10}">
						<div class="paginator" role="navigation">
							<div class="page-links">
								<c:forEach begin="0" end="${maxPageNoComplaintsTrueName-1 }" varStatus="status">
									<c:choose>
										<c:when test="${status.index==pageNoComplaintsTrueName }">
											<a class="act"
												href="customerservicecenter?pageIndex=${status.index}&showPage=complaintRealName">${status.count }</a>
										</c:when>
										<c:otherwise>
											<a href="customerservicecenter?pageIndex=${status.index}&showPage=complaintRealName">${status.count }</a>
										</c:otherwise>
									</c:choose>

								</c:forEach>
							</div>
							<div class="page-nav">
								<c:if test="${pageNoComplaintsTrueName>0 }">
									<a href="customerservicecenter?pageIndex=${pageNoComplaintsTrueName-1}&showPage=complaintRealName"
										class="nav-prev">前一页</a>
								</c:if>
								<c:if test="${pageNoComplaintsTrueName<maxPageNoComplaintsTrueName-1 }">
									<a href="customerservicecenter?pageIndex=${pageNoComplaintsTrueName+1}&showPage=complaintRealName"
										class="nav-next">后一页</a>
								</c:if>
							</div>
						</div>
					</c:if>
				</ol>
			</div>
		</div>
		<div style="float: left" id="nomalComplaint">
			<div class="content faq_list">
				<h2 style="text-align: center;">普通申诉单</h2>
				<input type="text"  placeholder="请输入账号" id="complaintNormalQueryText" value="${complaintNormalQueryText}">
				<button id="complaintNormalQueryBtn" >查询</button>
				<br>
				<ol  style="color:black; ">
					<c:forEach items="${complaintsNormal}" var="complaint"
						varStatus="status">
						<li id="${complaint.id}">&nbsp;申诉账号:${complaint.userAcc}
							<br>&nbsp;真实姓名:${complaint.trueName } <br>&nbsp;身份证号:${complaint.idNumber }
							<br>&nbsp;联系方式:${complaint.contact } <br>&nbsp;<span style="word-wrap:break-word">申诉信息:${complaint.complaintInfo }</span>
							<!-- 							<c:if test="${adminLvl>0&& empty complaint.answer}"> -->
							<!-- 								<button id="replyNormal" onclick="markComplaintId(${complaint.id})" -->
							<!-- 									style="float:right;margin-top: -3%">回复</button> -->
							<!-- 							</c:if> --> <c:if test="${adminLvl>0}">
								<button id="del" onclick="delComplaint(${complaint.id})"
									style="float:right;margin-top: -3%">删除</button>
							</c:if> <!-- 							<c:if test="${!empty complaint.answer}"> --> <!-- 								<br> -->
							<!-- 								<span>&nbsp;${complaint.answerName}回复：${complaint.answer}</span> -->
							<!-- 							</c:if> --></li>
					</c:forEach>
						<c:if test="${totalComplaintsNormal >10}">
						<div class="paginator" role="navigation">
							<div class="page-links">
								<c:forEach begin="0" end="${maxPageNoComplaintsNormal-1 }" varStatus="status">
									<c:choose>
										<c:when test="${status.index==pageNoComplaintsNormal }">
											<a class="act"
												href="customerservicecenter?pageIndex=${status.index}&showPage=complaintNormal">${status.count }</a>
										</c:when>
										<c:otherwise>
											<a href="customerservicecenter?pageIndex=${status.index}&showPage=complaintNormal">${status.count }</a>
										</c:otherwise>
									</c:choose>

								</c:forEach>
							</div>
							<div class="page-nav">
								<c:if test="${pageNoComplaintsNormal>0 }">
									<a href="customerservicecenter?pageIndex=${pageNoComplaintsNormal-1}&showPage=complaintNormal"
										class="nav-prev">前一页</a>
								</c:if>
								<c:if test="${pageNoComplaintsNormal<maxPageNoComplaintsNormal-1 }">
									<a href="customerservicecenter?pageIndex=${pageNoComplaintsNormal+1}&showPage=complaintNormal"
										class="nav-next">后一页</a>
								</c:if>
							</div>
						</div>
					</c:if>
				</ol>
			</div>
		</div>
		<div class="rms_d"></div>
	</div>
	<%@ include file="footer.jsp"%>
</body>
<script src="/products/passport/v2/js/jquery.js"></script>
<script type="text/javascript">
	
	$(document).ready(function() {

		var questionId;
		var complaintId;
		var typeFlag;
		var showPage; //标记要显示的div

		$("div:first").nextAll().not("#newQuestion").click(function() {
			$("#newQuestion").hide();
		});
		$("div:first").nextAll().not("#replyContent").click(function() {
			$("#replyContent").hide();
		});
		$("#realNameComplaint").hide();
		$("#nomalComplaint").hide();
		if ("${showPage}"== "question") {
			$("#message").show();
			$("#realNameComplaint").hide();
			$("#nomalComplaint").hide();
		}
		if ("${showPage}" == "complaintRealName") {
			$("#message").hide();
			$("#realNameComplaint").show();
			$("#nomalComplaint").hide();
		}
		if ("${showPage}" == "complaintNormal") {
			$("#message").hide();
			$("#realNameComplaint").hide();
			$("#nomalComplaint").show();
		}
	});

	function markQuestionId(msg) {
		questionId = msg;
		typeFlag = "question";
	}
	function markComplaintId(msg) {
		typeFlag = "complaint"
		complaintId = msg;
	}
	$("#reply").click(function() {
		$("#replyContent").show();
		$("#rContent").val("");
		return false;
	});
	$("#replyRealName").click(function() {
		$("#replyContent").show();
		$("#rContent").val("");
		return false;
	});
	$("#replyNormal").click(function() {
		$("#replyContent").show();
		$("#rContent").val("");
		return false;
	});
	$("#add").click(function() {
		$("#newQuestion").show();
		$("#content").val("");
		if ($.trim(${contact}) == "") {
			$("#contact").val("");
		}
		return false;
	});
	function saveQuestion() {
		if ($.trim($("#content").val()) == "") {
			alert("留言不能为空");
			return;
		}
		 var  re = /^1\d{10}$/;
		if (!re.test($.trim($("#contact").val()))) {
			alert("请输入正确的手机号码");
			return;
		}
		$.ajax({
			url : "/products/addQuestion",
			async : false, //异步：true;同步: false
			cache : false,
			data : {
				"content" : $("#content").val(),
				"contact" : $("#contact").val()
			},
			dataType : "json", //参数有"json","text"
			type : 'POST',
			success : function(msg) {
				if ("1" == msg) {
					$("#newQuestion").hide();
					location.reload();
				} else {
					alert("保存失败,请联系管理员");
				}
			} // 回调函数
		});
	}
	function saveReply() {
		if ($("#rContent").val() == "") {
			alert("回复不能为空");
			return;
		}
		var param = {};
		param.content = $("#rContent").val();
		param.typeFlag = typeFlag;
		if ("question" == typeFlag) {
			param.id = questionId;
		}
		if ("complaint" == typeFlag) {
			param.id = complaintId;
		}
		$.ajax({
			url : "/products/addReply",
			async : false, //异步：true;同步: false
			cache : false,
			data : param,
			dataType : "json", //参数有"json","text"
			type : 'POST',
			success : function(msg) {
				if ("1" == msg) {
					$("#replyContent").hide();
					location.reload();
				} else {
					alert("保存失败,请联系管理员");
				}
			} // 回调函数
		});
	}
	function del(msg) {
		$.ajax({
			url : "/products/delQuestion",
			async : false, //异步：true;同步: false
			cache : false,
			data : {
				"id" : msg
			},
			dataType : "json", //参数有"json","text"
			type : 'POST',
			success : function(msg) {
				location.reload();
			} // 回调函数
		});
	}
	function messageBtn() {
		$("#message").show();
		$("#realNameComplaint").hide();
		$("#nomalComplaint").hide();

		showPage="question";
		window.open("/products/customerservicecenter?pageIndex=0&showPage=question",'_self');
	}
	function realNameComplaintBtn() {
		$("#message").hide();
		$("#realNameComplaint").show();
		$("#nomalComplaint").hide();

		showPage="complaintRealName";
		window.open("/products/customerservicecenter?pageIndex=0&showPage=complaintRealName",'_self');
	}
	function nomalComplaintBtn() {
		$("#message").hide();
		$("#realNameComplaint").hide();
		$("#nomalComplaint").show();

		showPage="complaintNormal";
		window.open("/products/customerservicecenter?pageIndex=0&showPage=complaintNormal",'_self');
	}
	function delComplaint(id) {
		$.ajax({
			url : "/products/delComplaint",
			async : false, //异步：true;同步: false
			cache : false,
			data : {
				"id" : id
			},
			dataType : "text", //参数有"json","text"
			type : 'POST',
			success : function(msg) {
				$("#" + id).remove();
			}
		});
	}
	$("#complaintQueryBtn").click(function(){
		window.open("/products/customerservicecenter?pageIndex=${pageNo}&showPage=question&queryKey="+$("#complaintQueryText").val(),'_self');
	});
	$("#complaintRealNameQueryBtn").click(function(){
		window.open("/products/customerservicecenter?pageIndex=${pageNoComplaintsTrueName}&showPage=complaintRealName&queryKey="+$("#complaintRealNameQueryText").val(),"_self");
	});
	$("#complaintNormalQueryBtn").click(function(){
		window.open("/products/customerservicecenter?pageIndex=${pageNoComplaintsNormal}&showPage=complaintNormal&queryKey="+$("#complaintNormalQueryText").val(),"_self");
	});
</script>
</html>
